<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增元数据要素基础字典')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        .success{
            color: greenyellow;
        }
        .error{
            color: orangered;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-elementDict-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">中文名称：</label>
            <div class="col-sm-8">
                <input name="elementZh" class="form-control" type="text" required>
                <span class="elementZh"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">英文名称：</label>
            <div class="col-sm-8">
                <textarea name="elementEn" class="form-control" type="text" required style="height: 150px"></textarea>
                <span class="elementEn">（多个英文名称用小写逗号“,”分开）</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "product/elementDict"
    $("#form-elementDict-add").validate({
        focusCleanup: true
    });

    //内容校验
    var elementEnTmp = elementZh = 0;
    $("textarea[name=elementEn]").on('change',function () {
        var text = $("textarea[name=elementEn]").val();
        var elementEn = [[${elementEn}]]
        if ($.common.isEmpty(text)){
            $(".elementEn").addClass('error').removeClass('success').html("请填写英文名称");elementEnTmp = 0;
        }else if (elementEn.includes(text)){
            $(".elementEn").addClass('error').removeClass('success').html("该值不可用，系统中已存在！");elementEnTmp = 0;
        }else {
            $(".elementEn").addClass('success').removeClass('error').html("验证通过");elementEnTmp = 1;
        }
    })
    $("input[name=elementZh]").on('change',function () {
        var text = $("input[name=elementZh]").val();
        if ($.common.isEmpty(text)){
            $(".elementZh").addClass('error').removeClass('success').html("请填写中文名称");elementZh = 0;
        }else {
            $(".elementZh").addClass('success').removeClass('error').html("验证通过");elementZh = 1;
        }
    })

    function submitHandler() {
        if (elementZh != 1 || elementEnTmp != 1){return;}
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-elementDict-add').serialize());
        }
    }

    $("input[name='createDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='updateDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>
